package com.guigu.liuzhireng.service.impl;

import com.guigu.liuzhireng.mapper.AccountroleMapper;
import com.guigu.liuzhireng.mapper.RoleMapper;
import com.guigu.liuzhireng.pojo.Accountrole;
import com.guigu.liuzhireng.pojo.Role;
import com.guigu.liuzhireng.service.AccountroleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountroleServiceImpl implements AccountroleService {

    @Autowired
    AccountroleMapper accountroleMapper;
    @Autowired
    RoleMapper roleMapper;

    @Override
    public Accountrole AccountroleOnt(Integer id) {
        return accountroleMapper.selectByPrimaryKey(id);
    }

    public List<Role> QueryAccountRole(String account)  {
        List<Role> roles = roleMapper.RoleAll(new Role());
        List<Accountrole> list =accountroleMapper.QueryAccountRole(account);

        for (Role r : roles) {
            for (Accountrole ar : list) {
                if (ar.getRoleid().equals(r.getRoleid())){
                    r.setTf(true);
                }
            }
        }
        return roles;
    }

    @Override
    public int DelAdd(List<Accountrole> accountroles, String accid) {
        int deletes = accountroleMapper.deletes(accid);
        int inserts = accountroleMapper.inserts(accountroles);
        return deletes+inserts;
    }
}
